#!/bin/bash
cd `dirname $0`

checkFile(){
  if [ ! -f "$1" ];then
    echo "Unable to locate $1"
    exit
  fi
}

checkPath(){
  if ! type -P $1 &> /dev/null ;then  #强制搜索外部命令
     echo "Unable to find $1 in path"
     exit
  fi
}

checkEnvironment(){
  checkPath java
  checkPath adb
  checkPath git
  #echo "Operate System \"$(uname)\""
  JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep 'version \"\(1\.8\|9\).*\"')
  ADB_VERSION=$(adb version 2>&1 | head -n 1 | grep 'version \(1\.0\.4\|5\).*')
  #echo "$JAVA_VERSION"
  if [ "$JAVA_VERSION" == "" ];then
    echo "Wrong java version, 1.8 or more is required"
    exit
  fi
  #echo "$ADB_VERSION"
  if [ "$ADB_VERSION" == "" ];then
    echo "Wrong adb version, 1.0.40 or more is required"
    exit
  fi
}
checkEnvironment

java -jar `pwd`/wtk.jar $1 $2 $3 $4 $5 $6 $7 $8 $9




